package PropertiesText;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

/*
    配置的文件写在项目里，不然很容易找不到报错
 */
public class Demo {
    public static void main(String[] args) throws IOException {
        method();
        //method2();
    }

    /**
     * 将键值对写入到配置文件中
     * @throws IOException
     */
    private static void method2() throws IOException {
        Properties pro = new Properties();
        pro.setProperty("陈志伟","21");
        pro.setProperty("袁晓强","21");
        pro.setProperty("于飞正","23");
        pro.store(new FileWriter("after_buy\\stu.properties"),"xueSheng");
    }

    /**
     * 读取配置文件中的键值对
     * @throws IOException
     */
    private static void method() throws IOException {
        Properties pro = new Properties();
        pro.load(new FileReader("after_buy\\Pro.properties"));
        System.out.println(pro);
    }
}
